import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mvvm_provider/routers/home_router.dart';
import 'package:mvvm_provider/routers/navigator_utils.dart';
import '../../../base/base_stateful_page.dart';

class ClassicCasePage extends BasePage {
  const ClassicCasePage({super.key});

  @override
  BasePageState<BasePage> getState() => _ClassicCasePageState();
}

class _ClassicCasePageState extends BasePageState<ClassicCasePage> {
  final List<String> _list = ['小说收藏案例'];
  @override
  void initState() {
    super.initState();
    super.pageTitle = '经典案例';
    isBack = false;
  }

  @override
  Widget left() {
    return const SizedBox();
  }

  @override
  Widget buildPage(BuildContext context) {
    return ListView.builder(
      cacheExtent: 20,
      physics: const BouncingScrollPhysics(),
      reverse: false,
      itemCount: _list.length,
      itemBuilder: (BuildContext context, int index) {
        return CaseItem(
          title: _list[index],
          tab: () {
            NavigatorUtils.push(context, HomeRouter.collectionPage);
          },
        );
      },
    );
  }
}

class CaseItem extends StatelessWidget {
  final String title;
  final Function tab;
  const CaseItem({super.key, required this.title, required this.tab});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => tab(),
      child: Container(
        alignment: Alignment.center,
        decoration: BoxDecoration(color: Colors.blue, borderRadius: BorderRadius.circular(6.h)),
        padding: EdgeInsets.symmetric(horizontal: 18.w, vertical: 12.h),
        margin: EdgeInsets.only(left: 18.w, right: 18.w, top: 12.h),
        child: Text(
          title,
          style: TextStyle(fontSize: 14.sp, color: Colors.white, fontWeight: FontWeight.w400),
        ),
      ),
    );
  }
}
